package com.youku.core.view.components
{
   import flash.display.Sprite;
   import com.youku.core.view.interfaces.IVideo;
   import com.youku.interfaces.IPlayListData;
   import com.youku.core.model.vo.VideoSegmentData;
   import flash.net.NetConnection;
   import flash.net.NetStream;
   import flash.utils.Timer;
   import flash.net.URLLoader;
   import com.youku.utils.DelayTimer;
   import com.youku.PlayerConfig;
   import flash.events.NetStatusEvent;
   import com.youku.events.BasePlayerEvent;
   import com.youku.core.view.events.BaseVideoEvent;
   import flash.events.TimerEvent;
   import com.youku.utils.Log;
   import com.youku.P2PConfig;
   import com.youku.utils.Tweener;
   import com.youku.utils.GetUrl;
   import flash.events.Event;
   import flash.events.IOErrorEvent;
   import flash.events.SecurityErrorEvent;
   import flash.events.HTTPStatusEvent;
   import flash.net.URLRequest;
   import com.adobe.json.JSON;
   import flash.media.SoundTransform;
   import com.youku.data.PlayerConstant;
   import flash.utils.getTimer;
   
   public class BaseVideo extends Sprite implements IVideo
   {
      
      public function BaseVideo() {
         super();
         this._duration = 0;
         this._lastCanSeekTime = 0;
         this._jumpT = 0;
         this._updateJumpT = false;
         this._storeVolume = 0;
         this._started = false;
         this._connected = false;
         this._closed = true;
         this._waitPause = false;
         this._checkLoadBufferFullTimer = new Timer(50);
         this._checkLoadBufferFullTimer.addEventListener(TimerEvent.TIMER,this.onCheckLoadBufferFullTimer);
         this._playOver = false;
         this._preloadDone = false;
         this._oldTotalSize = -1;
         this._code2002Sent = false;
         this._code3004Sent = false;
         this._networkMayHaveProblem = false;
         this._connectTimer = new Timer(this._connectTimeout);
         this._sendBufferLengthTimer = new Timer(50);
         this._sendBufferLengthTimer.addEventListener(TimerEvent.TIMER,this.onSendBufferLengthTimer);
         this._mockBufferTimer = new Timer(2 * 1000);
         this._mockBufferTimer.addEventListener(TimerEvent.TIMER,this.onMockBufferTimer);
         this._isBufferEmpty = false;
         this._blocking = false;
         this._actionList = new Array();
         this._vh = 240;
         this._vw = 320;
         this._loadStartTime = -1;
         this._loadStartSize = -1;
         this._speed = 0;
         this._currSpeed = 0;
         this._useJumpTime = false;
         this._useJumpTimeT = 0;
         this._earlyStop = false;
         this._keyframes = new Array();
         this._special = false;
      }
      
      public static var CLOSE_BYTES:Number = 0;
      
      public static var BV_CLOSE_BYTES:Number = 0;
      
      protected var _playListData:IPlayListData;
      
      protected var _videoSegment:VideoSegmentData;
      
      protected var _num:int;
      
      protected var _vw:Number;
      
      protected var _vh:Number;
      
      protected var _nc:NetConnection;
      
      protected var _nsObj:Object;
      
      protected var _ns:NetStream;
      
      protected var _duration:Number;
      
      protected var _jumpT:Number;
      
      protected var _started:Boolean;
      
      protected var _connected:Boolean;
      
      protected var _closed:Boolean;
      
      protected var _waitPause:Boolean;
      
      protected var _playOver:Boolean;
      
      protected var _lastCanSeekTime:Number;
      
      protected var _oldTotalSize:Number;
      
      protected var _networkMayHaveProblem:Boolean;
      
      protected var _code2002Sent:Boolean;
      
      protected var _code3004Sent:Boolean;
      
      protected var _loadStartTime:Number;
      
      protected var _loadStartSize:Number;
      
      protected var _speed:Number;
      
      protected var _currSpeed:Number;
      
      protected var _storeVolume:Number;
      
      protected var _preloadDone:Boolean;
      
      protected var _blocking:Boolean;
      
      protected var _actionList:Array;
      
      protected var _connectTimer:Timer;
      
      protected var _connectTimeout:Number = 15000.0;
      
      protected var _reconnectCount:Number = 2;
      
      protected var _reconnectURL:String = "";
      
      protected var _isBufferEmpty:Boolean = false;
      
      protected var _isRealBuffer:Boolean = true;
      
      protected var _mockBufferTimer:Timer;
      
      protected var _mockBufferCount:Number = 0;
      
      protected var _mockBufferLimit:Number = 0;
      
      protected var _sendBufferLengthTimer:Timer;
      
      protected var _checkLoadBufferFullTimer:Timer;
      
      protected var _useJumpTime:Boolean = false;
      
      protected var _useJumpTimeT:int = 0;
      
      protected var _updateJumpT:Boolean = false;
      
      protected var _fileurlLoader:URLLoader;
      
      protected var _fileurlLoaderStatus:int = 0;
      
      protected var _fileurlLoadTimer:Timer;
      
      protected var _fileurlLoadTimeout:Number = 15000.0;
      
      protected var _special:Boolean = false;
      
      protected var _requestStartTime:Number;
      
      protected var _delayTimer:DelayTimer;
      
      protected var _innerSeek:Boolean;
      
      protected var _reload:Boolean;
      
      protected var _earlyStop:Boolean = false;
      
      protected var NORMAL_BUFFER_TIME:int = 30;
      
      protected var EMPTY_BUFFER_TIME:int = 2;
      
      protected var _keyframes:Array;
      
      protected var _isGotMetadata:Boolean = false;
      
      protected var HTTP_EARLY_REQUEST_ERROR_CODE:int = 503;
      
      public function init(param1:VideoSegmentData, param2:int) : void {
         this._videoSegment = param1;
         this._num = param2;
         this._playListData = PlayerConfig.playListData;
         this.createItems();
         this.addEvents();
      }
      
      protected function createItems() : void {
      }
      
      protected function addEvents() : void {
         this._nsObj.onMetaData = function(param1:Object):void
         {
            onVideoMetaData(param1);
         };
         this._ns.addEventListener(NetStatusEvent.NET_STATUS,this.onNetStatus);
         this._delayTimer.addEventListener(DelayTimer.DELAY_EVENT,this.onDelayEvent);
      }
      
      protected function onDelayEvent(param1:BasePlayerEvent) : void {
         var _loc2_:int = param1.data.num;
         var _loc3_:int = param1.data.dt;
         var _loc4_:BaseVideoEvent = new BaseVideoEvent(BaseVideoEvent.PLAY_START,
            {
               "num":_loc2_,
               "dt":_loc3_
            });
         dispatchEvent(_loc4_);
      }
      
      protected function onConnectTimeOut(param1:TimerEvent) : void {
         this._connectTimer.stop();
         this._reconnectCount--;
         if(this._reconnectCount > 0)
         {
            this.connectVideo(true);
         }
         else
         {
            this.loadError();
         }
      }
      
      protected function loadError() : void {
         this.close();
         var _loc1_:BaseVideoEvent = new BaseVideoEvent(BaseVideoEvent.PLAY_LOAD_ERROR,{"num":this.num});
         dispatchEvent(_loc1_);
      }
      
      protected function onVideoMetaData(param1:Object) : void {
         var _loc3_:* = 0;
         var _loc4_:Array = null;
         var _loc5_:* = 0;
         this._isGotMetadata = true;
         this._vw = !param1.width?320:param1.width;
         this._vh = !param1.height?240:param1.height;
         if(this._updateJumpT)
         {
            this._updateJumpT = false;
            if(this._playListData.fileType == "mp4")
            {
               this._jumpT = this._videoSegment.seconds - param1.duration;
            }
         }
         this._duration = param1.duration;
         this._lastCanSeekTime = param1.duration - 1;
         if(this._playListData.fileType == "flv" || this._playListData.fileType == "hd2")
         {
            if(param1.lastkeyframetimestamp)
            {
               this._lastCanSeekTime = param1.lastkeyframetimestamp;
            }
            else if(param1.keyframes)
            {
               _loc3_ = param1.keyframes.times.length;
               if(_loc3_ > 0)
               {
                  this._lastCanSeekTime = param1.keyframes.times[_loc3_ - 1];
               }
            }
            
            if(param1.keyframes)
            {
               this._keyframes = param1.keyframes.times.reverse();
            }
         }
         else if(this._playListData.fileType == "mp4")
         {
            if(param1.lastkeyframetimestamp)
            {
               this._lastCanSeekTime = param1.lastkeyframetimestamp;
               Log.log("seektime","" + this._lastCanSeekTime);
            }
            if((param1.seekpoints) && param1.seekpoints.length > 0)
            {
               _loc4_ = [];
               _loc5_ = 0;
               while(_loc5_ < param1.seekpoints.length)
               {
                  _loc4_.push(param1.seekpoints[_loc5_].time);
                  _loc5_++;
               }
               _loc4_.sort(Array.NUMERIC | Array.DESCENDING);
               this._lastCanSeekTime = _loc4_[0];
               this._lastCanSeekTime = this._lastCanSeekTime + this._jumpT;
               this._keyframes = _loc4_;
            }
         }
         
         var _loc2_:BaseVideoEvent = new BaseVideoEvent(BaseVideoEvent.GOT_METADATA,{"num":this.num});
         dispatchEvent(_loc2_);
         this._blocking = false;
         this.checkWaitingActions();
      }
      
      protected function checkWaitingActions() : void {
         if(this._actionList.length == 0)
         {
            return;
         }
         if(this._blocking)
         {
            return;
         }
         var _loc1_:Object = this._actionList.shift();
         if(_loc1_.type == "pause")
         {
            this.pause();
            this.checkWaitingActions();
         }
         else if(_loc1_.type == "resume")
         {
            this.resume();
            this.checkWaitingActions();
         }
         else if(_loc1_.type == "seek")
         {
            if(_loc1_.jump)
            {
               this.seek(_loc1_.t);
            }
            else
            {
               this.mockSeek(_loc1_.t);
            }
         }
         
         
      }
      
      protected function addAction(param1:Object) : void {
         var _loc2_:Array = null;
         var _loc3_:* = 0;
         if(param1 == null)
         {
            return;
         }
         if(param1.type == "pause" || param1.type == "resume")
         {
            this._actionList.push(param1);
         }
         else if(param1.type == "seek")
         {
            _loc2_ = new Array();
            _loc3_ = 0;
            while(_loc3_ < this._actionList.length)
            {
               if(this._actionList[_loc3_].type != "seek")
               {
                  _loc2_.push(this._actionList[_loc3_]);
               }
               _loc3_++;
            }
            this._actionList = _loc2_;
            this._actionList.push(param1);
         }
         
      }
      
      protected function onNetStatus(param1:NetStatusEvent) : void {
         switch(param1.info.code)
         {
            case "NetStream.Play.Start":
               this.onNetStreamPlayStartEvent();
               break;
            case "NetStream.Play.Stop":
               this.onNetStreamPlayStopEvent();
               break;
            case "NetStream.Buffer.Full":
               this.onBufferFullEvent();
               break;
            case "NetStream.Buffer.Empty":
               break;
            case "NetStream.Play.StreamNotFound":
               this.loadError();
               return;
            case "NetStream.Seek.InvalidTime":
               this._ns.seek(param1.info.details);
               break;
         }
      }
      
      protected function onNetStreamPlayStartEvent() : void {
         this._connectTimer.stop();
         this._connected = true;
         this._blocking = false;
         if(this._waitPause)
         {
            this._waitPause = false;
            this._ns.pause();
            this._checkLoadBufferFullTimer.reset();
            this._checkLoadBufferFullTimer.start();
         }
         dispatchEvent(new BaseVideoEvent(BaseVideoEvent.CONNECT_DONE));
      }
      
      protected function onCheckLoadBufferFullTimer(param1:TimerEvent) : void {
         var _loc2_:Number = this._duration;
         if(this._playListData.fileType == "mp4")
         {
            _loc2_ = this._jumpT + this._duration;
         }
         if(this._ns.bufferLength > this._ns.bufferTime || this._jumpT + this._ns.bufferLength >= _loc2_ - 1)
         {
            dispatchEvent(new BaseVideoEvent(BaseVideoEvent.LOAD_BUFFER_FULL));
            this._checkLoadBufferFullTimer.stop();
         }
      }
      
      protected function onNetStreamPlayStopEvent() : void {
         var _loc1_:* = NaN;
         if(this._ns.time == 0 && this._duration == 0)
         {
            this.loadError();
            return;
         }
         if(this._ns.bytesLoaded < this._oldTotalSize)
         {
            this._playOver = false;
            this.dispatchEvent(new BaseVideoEvent(BaseVideoEvent.PLAY_MIDDLE_ERROR,{"num":this.num}));
            return;
         }
         if(this._playOver)
         {
            return;
         }
         this.checkInvalidPlayEnd();
         if(this.reallyPlayEnd)
         {
            this._playOver = true;
            this.setVolume(0);
            this.dispatchEvent(new BaseVideoEvent(BaseVideoEvent.PLAY_OVER,{"num":this.num}));
            return;
         }
         this._playOver = false;
         this._earlyStop = true;
         _loc1_ = this._ns.time;
         this.playUnloadedPart(_loc1_);
      }
      
      protected function get reallyPlayEnd() : Boolean {
         if(Math.abs(this._ns.time - this._duration) < 2 || (this._earlyStop))
         {
            return true;
         }
         return false;
      }
      
      protected function checkInvalidBufferFull() : void {
         var _loc2_:Object = null;
         var _loc1_:Number = P2PConfig.NSBufferFullDiff;
         if(this._ns.bufferLength < this._ns.bufferTime - _loc1_)
         {
            Log.log("Warn","BaseVideo.checkInvalidBufferFull bufferLength=" + this._ns.bufferLength + " bufferTime=" + this._ns.bufferTime + " diff_threshod = " + _loc1_);
            _loc2_ = this.getInvalidParams("NetStream.Buffer.Full");
         }
      }
      
      protected function checkInvalidEmpty() : void {
         var _loc1_:Number = P2PConfig.NSBufferEmptyDiff;
         if(this._ns.bufferLength < _loc1_)
         {
            return;
         }
         Log.log("Warn","BaseVideo.checkInvalidEmpty bufferLength = " + this._ns.bufferLength + " max_valid = " + _loc1_);
         var _loc2_:Object = this.getInvalidParams("NetStream.Buffer.Empty");
      }
      
      protected function checkInvalidPlayEnd() : void {
         if(this.reallyPlayEnd)
         {
            return;
         }
         Log.log("Warn","BaseVideo. invalid Play.Stop bufferLength= " + this._ns.bufferLength + " buffertime= " + this._ns.bufferTime);
         var _loc1_:Object = this.getInvalidParams("NetStream.Play.Stop");
         dispatchEvent(new BaseVideoEvent(BaseVideoEvent.INVALID_PLAY_EVENT,_loc1_));
      }
      
      protected function cleanNetStream() : void {
         if(this._ns != null)
         {
            CLOSE_BYTES = CLOSE_BYTES + this._ns.bytesLoaded;
            this._ns.close();
            this._ns.removeEventListener(NetStatusEvent.NET_STATUS,this.onNetStatus);
            this._ns = null;
         }
      }
      
      protected function getInvalidParams(param1:String) : Object {
         var _loc2_:Object = {};
         _loc2_.num = this.num;
         _loc2_.type = param1;
         _loc2_.bufferlength = this._ns.bufferLength;
         _loc2_.buffertime = this._ns.bufferTime;
         _loc2_.duration = this._duration;
         _loc2_.nstime = this._ns.time;
         return _loc2_;
      }
      
      protected function onBufferFull() : void {
         var _loc1_:BaseVideoEvent = new BaseVideoEvent(BaseVideoEvent.BUFFER_FULL,{"num":this.num});
         dispatchEvent(_loc1_);
         this._mockBufferTimer.stop();
         this._sendBufferLengthTimer.stop();
         this._isBufferEmpty = false;
      }
      
      protected function onBufferFullEvent() : void {
         var delaytime:Number = NaN;
         var event:BaseVideoEvent = null;
         this.onBufferFull();
         this.checkInvalidBufferFull();
         if(!this._started)
         {
            this._started = true;
            delaytime = new Date().time - this._requestStartTime;
            event = new BaseVideoEvent(BaseVideoEvent.PLAY_START,
               {
                  "num":this.num,
                  "dt":delaytime
               });
            dispatchEvent(event);
            this.setVolume(this._storeVolume);
         }
         if(this._ns.bufferLength + 1 >= this._ns.bufferTime)
         {
            Tweener.to(this,0.1,{"onComplete":function():void
            {
               if(!_isBufferEmpty)
               {
                  _ns.bufferTime = NORMAL_BUFFER_TIME;
               }
            }});
         }
      }
      
      protected function onBufferEmpty(param1:Boolean = true) : void {
         var _loc2_:BaseVideoEvent = new BaseVideoEvent(BaseVideoEvent.BUFFER_EMPTY,
            {
               "num":this.num,
               "isRealBuffer":param1
            });
         this.dispatchEvent(_loc2_);
         this._isBufferEmpty = true;
         this._isRealBuffer = param1;
         this._mockBufferCount = 0;
         this._mockBufferLimit = int(Math.random() * 50 + 45);
         this._sendBufferLengthTimer.reset();
         this._sendBufferLengthTimer.start();
      }
      
      private function onSendBufferLengthTimer(param1:TimerEvent) : void {
         var _loc2_:Number = this._ns.bufferLength;
         var _loc3_:Number = this._ns.bufferTime;
         var _loc4_:Number = _loc2_ / _loc3_;
         if(!this._isRealBuffer)
         {
            this._mockBufferCount = this._mockBufferCount + int(Math.random() * 1.2);
            if(this._mockBufferCount >= this._mockBufferLimit)
            {
               this._mockBufferCount = this._mockBufferLimit;
            }
            _loc4_ = this._mockBufferCount / 100;
            _loc4_ = (this.loadedTime - this._jumpT) / _loc3_;
         }
         if(!this._isRealBuffer)
         {
            if(this.loadedTime - this._jumpT >= this._ns.bufferTime)
            {
               this.onBufferFull();
            }
         }
         else if(this._ns.bufferLength > this._ns.bufferTime)
         {
            this.onBufferFull();
         }
         
         this.dispatchEvent(new BaseVideoEvent(BaseVideoEvent.BUFFER_PERCENT,
            {
               "num":this.num,
               "per":_loc4_
            }));
      }
      
      private function onMockBufferTimer(param1:TimerEvent) : void {
         this._mockBufferTimer.stop();
         this.onBufferEmpty(false);
      }
      
      protected function pauseVideoForLoad() : void {
         if(this._waitPause)
         {
            this._ns.pause();
            this._ns.seek(0);
            this._waitPause = false;
         }
      }
      
      protected function getFileParameters() : String {
         var _loc1_:String = GetUrl.getFileParameters(this._num,this._playListData,this._videoSegment,this._useJumpTime,this._useJumpTimeT);
         return _loc1_;
      }
      
      public function getFileURL(param1:Boolean) : String {
         var _loc2_:* = "k.youku.com/player/getFlvPath";
         this._useJumpTime = param1;
         _loc2_ = _loc2_ + this.getFileParameters();
         _loc2_ = "http://" + _loc2_;
         return _loc2_;
      }
      
      protected function requestFileURL() : void {
         if(!this._fileurlLoader)
         {
            this._fileurlLoader = new URLLoader();
            this._fileurlLoader.addEventListener(Event.COMPLETE,this.onFileURLLoadComplete);
            this._fileurlLoader.addEventListener(IOErrorEvent.IO_ERROR,this.onFileURLLoadError);
            this._fileurlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onFileURLLoadError);
            this._fileurlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS,this.onFileURLStatus);
         }
         if(!this._fileurlLoadTimer)
         {
            this._fileurlLoadTimer = new Timer(this._fileurlLoadTimeout);
            this._fileurlLoadTimer.addEventListener(TimerEvent.TIMER,this.onFileURLLoadError);
         }
         var _loc1_:* = "http://k.youku.com/player/getFlvPath";
         _loc1_ = _loc1_ + this.getFileParameters();
         _loc1_ = _loc1_ + "&yxon=1&special=true";
         this._fileurlLoader.load(new URLRequest(_loc1_));
         this._fileurlLoadTimer.reset();
         this._fileurlLoadTimer.start();
      }
      
      private function onFileURLStatus(param1:HTTPStatusEvent) : void {
         if(param1 != null)
         {
            this._fileurlLoaderStatus = param1.status;
         }
      }
      
      private function onFileURLLoadError(param1:Event) : void {
         var e:Event = param1;
         this._fileurlLoadTimer.stop();
         try
         {
            this._fileurlLoader.close();
         }
         catch(e:Error)
         {
         }
         if(this._fileurlLoaderStatus == this.HTTP_EARLY_REQUEST_ERROR_CODE)
         {
            this.close();
            this.dispatchEvent(new BaseVideoEvent(BaseVideoEvent.EARLY_REQUEST_ERROR));
            return;
         }
         this.loadError();
      }
      
      private function onFileURLLoadComplete(param1:Event) : void {
         var _loc4_:Object = null;
         this._fileurlLoadTimer.stop();
         var _loc2_:String = this._fileurlLoader.data as String;
         var _loc3_:* = "";
         if(_loc2_)
         {
            _loc4_ = com.adobe.json.JSON.decode(_loc2_)[0];
            if(_loc4_.server == null)
            {
               this.loadError();
               return;
            }
            _loc3_ = _loc4_.server;
            if((this._special) || (this._useJumpTime))
            {
               _loc3_ = _loc3_ + "?";
               if(this._special)
               {
                  _loc3_ = _loc3_ + "special=true";
               }
               if(this._useJumpTime)
               {
                  _loc3_ = _loc3_ + ("&start=" + this._useJumpTimeT);
               }
            }
            this._ns.bufferTime = this.EMPTY_BUFFER_TIME;
            this._ns.play(_loc3_);
            return;
         }
         this.loadError();
      }
      
      public function close(param1:Boolean = true) : void {
         this.closeNS(param1);
         this._earlyStop = false;
         this._closed = true;
         this._waitPause = false;
         this._preloadDone = false;
         this._jumpT = 0;
         this._updateJumpT = false;
         this._networkMayHaveProblem = false;
         this._reconnectCount = 2;
         this._reconnectURL = "";
         this._special = false;
         this._connectTimer.stop();
         this._mockBufferTimer.stop();
         this._sendBufferLengthTimer.stop();
         this._checkLoadBufferFullTimer.stop();
      }
      
      public function resetNS() : void {
         this._closed = true;
         this.checkNSVideo();
      }
      
      protected function checkNSVideo() : void {
         this.closeNS();
         this.addEvents();
      }
      
      protected function closeBasicNS(param1:Boolean = true) : void {
         BV_CLOSE_BYTES = BV_CLOSE_BYTES + this._ns.bytesLoaded;
         this._ns.close();
         this._ns.removeEventListener(NetStatusEvent.NET_STATUS,this.onNetStatus);
      }
      
      protected function closeNS(param1:Boolean = true) : void {
         if(this._ns)
         {
            this.closeBasicNS(param1);
         }
         this._started = false;
         this._connected = false;
         this._loadStartSize = -1;
         this._loadStartTime = -1;
         this._oldTotalSize = -1;
         this._speed = 0;
         this._currSpeed = 0;
         this._blocking = false;
         this._useJumpTime = false;
         this._useJumpTimeT = 0;
         this._sendBufferLengthTimer.stop();
         if(this._fileurlLoadTimer)
         {
            this._fileurlLoadTimer.stop();
         }
         if(this._fileurlLoader)
         {
            try
            {
               this._fileurlLoader.close();
            }
            catch(e:Error)
            {
            }
         }
         this._fileurlLoaderStatus = 0;
      }
      
      protected function setVolume(param1:Number) : void {
         var st:SoundTransform = null;
         var v:Number = param1;
         if(this._ns)
         {
            try
            {
               st = this._ns.soundTransform;
               st.volume = v;
               this._ns.soundTransform = st;
            }
            catch(e:Error)
            {
            }
         }
      }
      
      public function seek(param1:Number) : void {
         var _loc2_:* = true;
         this._waitPause = false;
         this.realSeek(param1,_loc2_);
      }
      
      public function mockSeek(param1:Number) : void {
         var _loc2_:* = false;
         this._waitPause = false;
         this.realSeek(param1,_loc2_);
      }
      
      public function seekLoad(param1:Number) : void {
         var _loc2_:* = true;
         this._waitPause = true;
         this.realSeek(param1,_loc2_,true);
      }
      
      protected function realSeek(param1:Number, param2:Boolean, param3:Boolean = false) : void {
         this._playOver = false;
         var _loc4_:Boolean = this.checkBlocking(param1,param2);
         if(_loc4_)
         {
            return;
         }
         var param1:Number = this.checkReload(param1,param2,param3);
         if(this._innerSeek)
         {
            this.playLoadedPart(param1);
         }
         else if(this._reload)
         {
            this.playUnloadedPart(param1);
         }
         
      }
      
      protected function checkBlocking(param1:Number, param2:Boolean) : Boolean {
         var _loc3_:Object = null;
         if(this._blocking)
         {
            _loc3_ = {};
            _loc3_.type = "seek";
            _loc3_.t = param1;
            _loc3_.jump = param2;
            this.addAction(_loc3_);
            _loc3_ = {};
            _loc3_.type = "resume";
            this.addAction(_loc3_);
            return true;
         }
         return false;
      }
      
      protected function checkReload(param1:Number, param2:Boolean, param3:Boolean) : Number {
         var _loc4_:* = false;
         var _loc5_:* = false;
         if(param1 > this._videoSegment.seconds)
         {
            param1 = this._videoSegment.seconds;
         }
         if(param1 > this._lastCanSeekTime && !(this._lastCanSeekTime == 0))
         {
            param1 = this._lastCanSeekTime;
         }
         if(param3)
         {
            this._innerSeek = false;
            this._reload = true;
            return param1;
         }
         if(param1 <= this._videoSegment.seconds)
         {
            if(param2)
            {
               if(!this._closed && param1 >= this._jumpT && param1 <= this.loadedTime)
               {
                  if(this.loadedTime > 0)
                  {
                     _loc4_ = true;
                     _loc5_ = false;
                  }
                  else
                  {
                     _loc4_ = false;
                     _loc5_ = true;
                  }
               }
               else
               {
                  _loc4_ = false;
                  _loc5_ = true;
               }
            }
            else if(!this._closed && param1 >= this._jumpT && param1 <= this.loadedTime && this.loadedTime > 0)
            {
               _loc4_ = true;
               _loc5_ = false;
            }
            
         }
         else
         {
            _loc4_ = false;
            _loc5_ = false;
         }
         this._innerSeek = _loc4_;
         this._reload = _loc5_;
         return param1;
      }
      
      protected function playLoadedPart(param1:Number) : void {
         this._closed = false;
         var _loc2_:Number = param1;
         if((this.isJump) && this._playListData.fileType == "mp4")
         {
            param1 = param1 - this._jumpT;
         }
         this._ns.bufferTime = this.EMPTY_BUFFER_TIME;
         var _loc3_:Number = param1;
         if(PlayerConfig.isSeekToKeyframe == true)
         {
            param1 = this.getKeyframe(param1);
         }
         this._ns.seek(param1);
         this.checkWaitingActions();
         this.setVolume(this._storeVolume);
      }
      
      protected function playUnloadedPart(param1:Number) : void {
         this._closed = false;
         this._jumpT = param1;
         this._updateJumpT = true;
         this.createItems();
         this.connectVideo(true);
      }
      
      protected function connectVideo(param1:Boolean) : void {
         this.checkNSVideo();
         this._blocking = true;
         this.dispatchEvent(new BaseVideoEvent(BaseVideoEvent.CONNECT_START));
         this.playVideo(param1);
         this.setVolume(0);
         this._mockBufferTimer.reset();
         this._mockBufferTimer.start();
         this._connectTimer.reset();
         this._connectTimer.start();
      }
      
      protected function playVideo(param1:Boolean) : void {
         this._useJumpTime = param1;
         this._useJumpTimeT = this._jumpT;
         this._special = false;
         if((this._playListData.threeD) || PlayerConfig.specialType == PlayerConstant.SPECIAL_TYPE_JIETU)
         {
            this._special = true;
         }
         this._ns.bufferTime = this.EMPTY_BUFFER_TIME;
         this._ns.checkPolicyFile = true;
         this.requestFileURL();
         this._requestStartTime = new Date().time;
         if(P2PConfig.isP2PPlayer)
         {
            if(this._delayTimer)
            {
               this._delayTimer.start();
            }
         }
      }
      
      public function play(param1:Boolean = false) : void {
         this._playOver = false;
         this._closed = false;
         if(this._connected)
         {
            this._waitPause = false;
            this._ns.bufferTime = this.EMPTY_BUFFER_TIME;
            this.resume();
            this.setVolume(this._storeVolume);
         }
         else
         {
            if((this._preloadDone) && (this._waitPause))
            {
               this._waitPause = false;
               return;
            }
            this.connectVideo(false);
         }
         this._jumpT = 0;
      }
      
      public function pause() : void {
         var _loc1_:Object = null;
         if(this._blocking)
         {
            _loc1_ = {};
            _loc1_.type = "pause";
            this.addAction(_loc1_);
         }
         else
         {
            this._ns.pause();
         }
      }
      
      public function resume() : void {
         var _loc1_:Object = null;
         if(this._blocking)
         {
            _loc1_ = {};
            _loc1_.type = "resume";
            this.addAction(_loc1_);
         }
         else
         {
            this._ns.resume();
         }
      }
      
      public function setToHead() : void {
         if(this._ns.time > 0)
         {
            if(this._playListData.fileType == "mp4")
            {
               this._ns.seek(0);
            }
            else
            {
               this._ns.seek(this._jumpT);
            }
            this._ns.pause();
         }
      }
      
      public function load() : void {
         this._started = false;
         this._connected = false;
         this._playOver = false;
         this._closed = true;
         this._preloadDone = true;
         this._waitPause = true;
         this.seekLoad(0);
         this.setVolume(0);
         this._jumpT = 0;
         this._updateJumpT = true;
      }
      
      public function get segmentData() : VideoSegmentData {
         return this._videoSegment;
      }
      
      public function get closed() : Boolean {
         return this._closed;
      }
      
      public function set volume(param1:Number) : void {
         this._storeVolume = param1;
         this.setVolume(param1);
      }
      
      public function set defaultVolume(param1:Number) : void {
         this._storeVolume = param1;
      }
      
      public function get nsTime() : Number {
         var _loc1_:Number = 0;
         if(this._playListData.fileType == "mp4")
         {
            _loc1_ = this._ns.time + this._jumpT;
         }
         else if(this._started)
         {
            _loc1_ = this._ns.time;
         }
         else
         {
            _loc1_ = this._jumpT;
         }
         
         return _loc1_;
      }
      
      public function get loadedTime() : Number {
         var _loc1_:* = NaN;
         if(this._ns.bytesTotal)
         {
            _loc1_ = (this._duration - this._jumpT) * this._ns.bytesLoaded / this._ns.bytesTotal + this._jumpT;
            if(this._playListData.fileType == "mp4")
            {
               _loc1_ = this._duration * this._ns.bytesLoaded / this._ns.bytesTotal + this._jumpT;
            }
         }
         else
         {
            _loc1_ = this._jumpT;
         }
         return _loc1_;
      }
      
      public function updateStatus() : void {
         var _loc1_:* = NaN;
         var _loc2_:* = NaN;
         if(this._ns.bytesLoaded > 0 && this._ns.bytesTotal > 0)
         {
            if(this._oldTotalSize < this._ns.bytesTotal)
            {
               this._oldTotalSize = this._ns.bytesTotal;
            }
         }
         if((this._ns.bytesLoaded > 0 || this._ns.bytesTotal > 0) && this._ns.bytesLoaded < this._ns.bytesTotal)
         {
            if(this._loadStartSize == -1)
            {
               this._loadStartSize = this._ns.bytesLoaded;
               this._loadStartTime = getTimer();
            }
            else
            {
               _loc1_ = this._ns.bytesLoaded - this._loadStartSize;
               _loc2_ = getTimer() - this._loadStartTime;
               this._speed = _loc1_ / (_loc2_ / 1000);
               this._currSpeed = this._speed;
            }
         }
         else
         {
            this._currSpeed = 0;
         }
      }
      
      public function get bytesLoaded() : Number {
         return this._ns.bytesLoaded;
      }
      
      public function get bytesTotal() : Number {
         return this._ns.bytesTotal;
      }
      
      public function get droppedFrames() : Number {
         if(this._ns == null || !this._ns.hasOwnProperty("info"))
         {
            return 0;
         }
         var droppedFrames:Number = 0;
         try
         {
            droppedFrames = this._ns.info.droppedFrames;
         }
         catch(e:Error)
         {
         }
         return droppedFrames;
      }
      
      public function get FPS() : Number {
         if(this._ns == null)
         {
            return 0;
         }
         return this._ns.currentFPS;
      }
      
      public function get totalTime() : Number {
         return this._videoSegment.seconds;
      }
      
      public function get num() : Number {
         return this._num;
      }
      
      public function get loadOver() : Boolean {
         if((this._connected) && this._ns.bytesLoaded > 0)
         {
            if(this._ns.bytesLoaded == this._ns.bytesTotal)
            {
               if(this._ns.bytesLoaded < this._oldTotalSize)
               {
                  return false;
               }
               return true;
            }
            return false;
         }
         return false;
      }
      
      public function get rtmpLoadOver() : Boolean {
         return false;
      }
      
      public function get jumpT() : Number {
         return this._jumpT;
      }
      
      protected function getKeyframe(param1:Number) : Number {
         var _loc3_:* = 0;
         var _loc4_:* = NaN;
         var _loc2_:Number = param1;
         if((this._keyframes) && this._keyframes.length > 0)
         {
            _loc3_ = 0;
            while(_loc3_ < this._keyframes.length)
            {
               _loc4_ = Number(this._keyframes[_loc3_]) - param1;
               if(_loc4_ <= 0)
               {
                  return Number(this._keyframes[_loc3_]);
               }
               _loc3_++;
            }
         }
         return _loc2_;
      }
      
      public function resetData(param1:VideoSegmentData) : void {
         this._videoSegment = param1;
         this.close();
         this._preloadDone = false;
         this._code2002Sent = false;
         this._code3004Sent = false;
         this._oldTotalSize = -1;
         this._networkMayHaveProblem = false;
         this._loadStartSize = -1;
         this._loadStartTime = -1;
         this._speed = 0;
         this._currSpeed = 0;
      }
      
      public function get preloadDone() : Boolean {
         if((this._preloadDone) && this._jumpT == 0)
         {
            return true;
         }
         return false;
      }
      
      public function get isJump() : Boolean {
         return this._jumpT == 0?false:true;
      }
      
      public function get code2002Sent() : Boolean {
         return this._code2002Sent;
      }
      
      public function set code2002Sent(param1:Boolean) : void {
         this._code2002Sent = param1;
      }
      
      public function get code3004Sent() : Boolean {
         return this._code3004Sent;
      }
      
      public function set code3004Sent(param1:Boolean) : void {
         this._code3004Sent = param1;
      }
      
      public function get oldTotalSize() : Number {
         return this._oldTotalSize;
      }
      
      public function get speed() : Number {
         return this._speed;
      }
      
      public function get currSpeed() : Number {
         return this._currSpeed;
      }
      
      public function get fileid() : String {
         if(this._videoSegment != null)
         {
            return this._videoSegment.fileId;
         }
         return "";
      }
      
      public function get ns() : NetStream {
         return this._ns;
      }
      
      public function get videoRealWidth() : Number {
         return this._vw;
      }
      
      public function get videoRealHeight() : Number {
         return this._vh;
      }
      
      public function get fileidTime() : Number {
         return 0;
      }
      
      public function get isGotMetadata() : Boolean {
         return this._isGotMetadata;
      }
   }
}
